/* GUI CONVERTED from rcshsov.p (converter v1.76) Tue Jan 29 20:38:54 2002 */
/* rcshsov.p  - PRE-SHIPPER WORKBENCH - SALES ORDER VALIDATION              */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.             */
/* $Revision: 1.6.1.7 $                                                         */
/*V8:ConvertMode=Maintenance                                                */
/* VERSION 8.6            CREATED: 09/24/97   BY: *K0JC*  John Worden       */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan       */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan       */
/* REVISION: 8.6E     LAST MODIFIED: 05/12/99   BY: *K20X* Satish Chavan    */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb              */
/* REVISION: 9.1      LAST MODIFIED: 09/06/00   BY: *N0RG* BalbeerS Rajput  */
/* Revision: 1.6.1.6     BY: Rajesh Kini        DATE: 05/18/01 ECO: *M16B*  */
/* $Revision: 1.6.1.7 $    BY: Mercy C.                 DATE: 01/24/02 ECO: *M1TT*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}
{gplabel.i}

/* Input parameters */
define input parameter abs_recid as recid no-undo.
define input parameter p-par_recid as recid no-undo.
define input parameter p-abs_format like abs_mstr.abs_format no-undo.
define input parameter p-sod_nbr like sod_det.sod_nbr no-undo.
define input parameter p-sod_line like abs_mstr.abs_line no-undo.
define input parameter p-shipto as character no-undo.

/* Output parameters */
define output parameter p-passed as logical no-undo.

/* Local variables */
define variable kit_comp      as   logical             no-undo.
define variable cons_ok       as   logical             no-undo.
define variable other_so      like so_mstr.so_nbr      no-undo.
define variable l_shipto_id   as   character           no-undo.
define variable l_addr        as   character           no-undo.

/* Buffers */
define buffer b1-abs_mstr for abs_mstr.

{rcinvtbl.i new}

p-passed = yes.

/* check for kits */
do for b1-abs_mstr:
   find first b1-abs_mstr where recid(b1-abs_mstr) = p-par_recid
      no-lock no-error.
   kit_comp = no.
   if available b1-abs_mstr and b1-abs_mstr.abs_id begins "i" then do:
      find abs_mstr
         where abs_mstr.abs_id = b1-abs_mstr.abs_id
         and abs_mstr.abs_shipfrom = b1-abs_mstr.abs_shipfrom
         no-lock no-error.
      if available abs_mstr then
         kit_comp = yes.
   end. /* if available b1-abs_mstr */
   /* ALLOW ADDING A KIT COMPONENT TO A KIT PARENT SHIPPER */
   /* INPUT PART NUMBER IS REQUIRED FOR KIT COMPONENT      */
   if available b1-abs_mstr and b1-abs_mstr.abs_id begins "i"
   then do:
      if abs_mstr.abs_item = "" then do:

         {pxmsg.i &MSGNUM=40 &ERRORLEVEL=3
            &MSGARG1=getTermLabel(""ITEM_NUMBER_IN_CONTAINER"",35)}
         /* BLANK NOT ALLOWED  */
         p-passed = no.
         return.
      end. /* abs_part = "" */
      if (b1-abs_mstr.abs_item = abs_mstr.abs_item) then do:
         {pxmsg.i &MSGNUM=599 &ERRORLEVEL=3 }
         /* CYCLIC RELATIONSHIP NOT ALLOWED */
         p-passed = no.
         return.
      end. /* if item = item */
   end. /* if available b1-abs_mstr */

   if available b1-abs_mstr then do:
      /* If shipper consolidation is no, then check whether we
       * are putting more than one SO on the shipper */
      if b1-abs_mstr.abs_cons_ship = "0" then do:
         run chk_abs_shp_cons
            (input b1-abs_mstr.abs_id,
            input b1-abs_mstr.abs_shipfrom,
            input "", input "",
            input p-sod_nbr,
            output cons_ok, output other_so).

         if not cons_ok then do:
            {pxmsg.i &MSGNUM=5825 &ERRORLEVEL=3
                     &MSGARG1=other_so}
            /*SHIPPER REFERENCES SALES ORDER #. CONSOLIDATION NOT PERMITTED*/
            p-passed = no.
            return.
         end. /* if not cons_ok */
      end. /* if abs_cons_ship = "0" */

      /* If invoice consolidation is to happen, then check
      for compatibility of SOs on the shipper */
      if can-find (first df_mstr where df_format = p-abs_format and
         df_type = "1" and df_inv = true)
      then do:
         run chk_abs_inv_cons
            (input b1-abs_mstr.abs_id,
             input b1-abs_mstr.abs_shipfrom,
             "",
             "",
             input p-sod_nbr,
             output cons_ok).
         if cons_ok = false then do:
            {pxmsg.i &MSGNUM=5835 &ERRORLEVEL=3}
            /* SALES ORDERS DO NOT MEET INVOICE CONSOLIDATION CONDITION */
            p-passed = no.
            return.
         end. /* if cons_ok = false */
      end. /* if can-find first ... */
   end. /* if available abs_mstr */
end. /* do for b1-abs_mstr */
find first abs_mstr where recid(abs_mstr) = abs_recid no-lock
   no-error.

/* VALIDATE IF VALID SALES ORDER LINE */
for first sod_det
      fields(sod_confirm sod_cum_qty sod_end_eff sod_line
             sod_nbr     sod_part    sod_sched   sod_site
             sod_btb_type sod_start_eff)
      where sod_nbr        = p-sod_nbr
      and string(sod_line) = p-sod_line
      no-lock:
end. /* FOR FIRST sod_det */

if available sod_det
   and sod_btb_type = "03"
then do:
   /* SHIPMENT NOT ALLOWED FOR DIR-SHIP EMT SALES ORDER */
   run DisplayMessage (input 3985,
                       input 3,
                       input '').
   p-passed = no.
   return.
end. /* IF AVAILABLE sod_det AND sod_btb_type = "03" */

if not available sod_det then do:
   /* SALES ORDER LINE DOES NOT EXIST */
   {pxmsg.i &MSGNUM=764 &ERRORLEVEL=3 &MSGARG1=p-sod_nbr}
   p-passed = no.
   return.
end.

if available sod_det and available abs_mstr then do:
   if sod_part <> abs_item then do:
      {pxmsg.i &MSGNUM=764 &ERRORLEVEL=3} /* SALES ORDER LINE DOES NOT EXIST */
      p-passed = no.
   end. /* sod_part <> abs_part */
end. /* avail sod_det and abs_mstr */

find so_mstr where so_nbr = sod_nbr no-lock.

/* VALIDATE SALES ORDER LINE SITE SAME AS SHIPFROM SITE */
if sod_site <> abs_mstr.abs_shipfrom then do:
   /* INVALID ORDER SHIP-FROM SITE */
   {pxmsg.i &MSGNUM=8228 &ERRORLEVEL=3 &MSGARG1=sod_site}
   p-passed = no.
   return.
end.

/* LOGIC TO FIND SHIP-TO OF THE ENTERED ADDRESS IF IT IS A DOCK */

for first ad_mstr
      fields(ad_addr ad_ref)
      where ad_addr = p-shipto
      no-lock:
end. /* FOR FIRST AD_MSTR */

for first ls_mstr
      fields(ls_addr ls_type)
      where ls_addr = ad_addr
      and  (ls_type = "ship-to"
      or    ls_type = "customer")
      no-lock:
end. /* FOR FIRST LS_MSTR */

do while not available ls_mstr and ad_ref > "":
   l_addr = ad_ref.
   for first ad_mstr
         fields(ad_addr ad_ref)
         where ad_addr = l_addr
         no-lock:
   end. /* FOR FIRST AD_MSTR */

   for first ls_mstr
         fields(ls_addr ls_type)
         where  ls_addr = ad_addr
         and   (ls_type = "ship-to"
         or     ls_type = "customer")
         no-lock:
   end. /* FOR FIRST LS_MSTR */

end. /* DO WHILE NOT AVAILABLE LS_MSTR */
l_shipto_id = ad_addr.

if  (so_ship <> l_shipto_id)
   and (so_ship <> p-shipto)
then do:
   /* INVALID ORDER SHIP-TO */
   {pxmsg.i &MSGNUM=8229 &ERRORLEVEL=3 &MSGARG1=so_ship}
   p-passed = no.
   return.
end. /* IF (SO_SHIP <> L_SHIPTO_ID... */

if so_sched and
   trim(substring(so_conrep,15,20)) <> global_db then do:
   /* YOU MUST BE IN DATABASE */
   {pxmsg.i &MSGNUM=8148 &ERRORLEVEL=3 &MSGARG1=trim(substring(so_conrep,15,20))}
   p-passed = no.
   return.
end.

if sod_start_eff[1] > today or sod_end_eff[1] < today then do:
   /* SCHEDULED ORDER IS NO LONGER EFFECTIVE */
   {pxmsg.i &MSGNUM=8138 &ERRORLEVEL=2}
   p-passed = no.
   return.
end.

if sod_cum_qty[1] >= sod_cum_qty[3] and sod_cum_qty[3] > 0 then do:
   /* CUM SHIPPED QTY > MAX ORDER QTY FOR ORDER SELECTED */
   {pxmsg.i &MSGNUM=8220 &ERRORLEVEL=2}
   p-passed = no.
   return.
end.

if (not sod_sched) and (not sod_confirm) then do:
   /* SALES ORDER LINE IS NOT SCHEDULED */
   {pxmsg.i &MSGNUM=621 &ERRORLEVEL=3}
   p-passed = no.
   return.
end.

if so_secondary then do:
   find trq_mstr no-lock where trq_doc_type = "SO"
      and trq_doc_Ref  = so_nbr
      and trq_add_ref  = ""
      and (trq_msg_type = "ORDRSP-I" or
      trq_msg_type = "ORDRSP-C") no-error.
   if available trq_mstr and trq_msg_type = "ORDRSP-C" then do:
      {pxmsg.i &MSGNUM=2834 &ERRORLEVEL=3}
      /*CHANGE ON EMT SO WITH PENDING CHANGE IS NOT ALLOWED */
      p-passed = no.
      return.
   end.
   if available trq_mstr and trq_msg_type = "ORDRSP-I" then do:
      {pxmsg.i &MSGNUM=2935 &ERRORLEVEL=3}
      /* MODIFICATION IS NOT ALLOWED - AWAITING PO ACKNOWLEDGEMENT */
      p-passed = no.
      return.
   end.
end.

{rcinvcon.i}

PROCEDURE DisplayMessage:
define input parameter ipMsgNum as integer no-undo.
define input parameter ipLevel  as integer no-undo.
define input parameter ipMsg1   as character no-undo.

{pxmsg.i &MSGNUM     = ipMsgNum
         &ERRORLEVEL = ipLevel
         &MSGARG1    = ipMsg1}
END PROCEDURE. /* PROCEDURE DisplayMessage */
